package com.gues.handler;

import org.apache.shiro.authc.AccountException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice
public class MyExceptionHandler {

    // 权限和角色
//    @ExceptionHandler(value = AuthorizationException.class)
//    public Result handleException(AuthorizationException e) {
//        return new Result(401, "您不是管理员, 您没有该权限");
//    }

    // 账号和密码
    @ExceptionHandler(value = UnknownAccountException.class)
    public Map<String, Object> unknownAccountException(AccountException e) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 403);
        map.put("msg", "账号或密码错误, 请重新输入");
        return map;
    }
    @ExceptionHandler(value = IncorrectCredentialsException.class)
    public Map<String, Object> incorrectCredentialsException(IncorrectCredentialsException e) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 403);
        map.put("msg", "账号或密码错误, 请重新输入");
        return map;
    }
}
